import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Http {

	public static void main(String args[]) {

		NewsRequest request = new NewsRequest();
		ArrayList<NewsDAO> list = request.getNewsList();
		for (int i = 0; i < list.size(); i++) {

			System.out.println(list.get(i).name);

		}
		if (true)
			return;
		String header = "http://news.xaufe.edu.cn";
		String url = "http://news.xaufe.edu.cn/GetNews.asp";
		Pattern p = Pattern
				.compile("<a href=(.*?) target=_blank title=(.*?)\"/");
		try {
			Matcher m = p.matcher(get(url));
			while (m.find()) {
				System.out.println(header
						+ m.group(1).substring(1, m.group(1).length() - 1));
				System.out.println(m.group(2).substring(1));
			}
		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

	static String get(String url) throws MalformedURLException, IOException {

		URLConnection conn = new URL(url).openConnection();
		String s;
		BufferedReader br = new BufferedReader(new InputStreamReader(
				conn.getInputStream()));
		StringBuffer b = new StringBuffer();
		while ((s = br.readLine()) != null) {
			b.append(s);
		}

		return b.toString();

	}

	static String post(String url, String p) throws MalformedURLException,
			IOException {

		URLConnection conn = new URL(url).openConnection();
		String s;
		conn.setDoInput(true);
		conn.setDoOutput(true);
		if (p != null)
			conn.getOutputStream().write(p.getBytes());
		BufferedReader br = new BufferedReader(new InputStreamReader(
				conn.getInputStream()));
		StringBuffer b = new StringBuffer();
		while ((s = br.readLine()) != null) {
			b.append(s);
		}

		return b.toString();

	}
}
